package com.example.feign.controller;

import com.example.feign.interfaces.TestFeign;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yangjianrong
 * @date 2020/7/3 17:23
 **/
@RestController
public class FeignController {

    @Autowired
    TestFeign testFeign;// 注入 Feign接口

    @HystrixCommand(fallbackMethod = "error")
    @RequestMapping(value = "/one")
    public String test(){
        return testFeign.testByFeign();
    }

    @HystrixCommand(fallbackMethod = "error")
    @RequestMapping(value = "/two")
    public String testOne(String msg){
        return testFeign.testOne(msg);
    }

    @HystrixCommand(fallbackMethod = "error")
    @RequestMapping(value = "/three")
    public String test1(){
        return testFeign.test1();
    }

    /**
     * 对应的参数个数及类型需要与原方法一致
     */
    public String error(String msg) {
        return msg+"=>error";
    }
    public String error() {
        return "=>error";
    }

}
